﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace pptrbt
{
    class pptrbnode
    {
        public int data;
        public pptrbnode left, right;
        public pptrbnode parent;
    
        public pptrbnode()
        {
            left = right = parent = null;
        }
        public pptrbnode(int pdata)
        {
            data = pdata;
            left = right = parent = null;
             intColor = RED;// by default, a new node is always red.
        }

       

        public int getheight()
        {
            int heightofsubtree = 0;

            int heightofbranch;

          
            if (left != null)
                heightofsubtree = left.getheight();

            if (right != null)
            {
                heightofbranch = right.getheight();

                if (heightofbranch > heightofsubtree)
                    heightofsubtree = heightofbranch;
            }

            return heightofsubtree + 1;

        }

        int x, y, r;

        public void calculatecoordinates(int start, int width, int ycord, int verticalinterval, int radius)
        {
            // prepare the x, y coordinates
            x = start + (width) / 2;
            y = ycord;
            r = radius;

            int interval = width / 2;

            if (left != null)
            {
                left.calculatecoordinates(start, interval, ycord + verticalinterval, verticalinterval, r);

            }
            if (right != null)
            {
                right.calculatecoordinates(start + interval, interval, ycord + verticalinterval, verticalinterval, r);
            }



        }


        //draw on ppt
        public void drawnode(int px, int py, pptgenerator ppg, int c)
        {
            try
            {
               
                ppg.newstring(x-13, y, Convert.ToString(data));

                
                ppg.newcircle(x,y, r, c);

                ppg.newline(px, py, x, y);


            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            if (left != null)
            {
                left.drawnode(x, y, ppg, Color);

            }

            if (right != null)
                right.drawnode(x, y, ppg, Color);

         
        }
        
        // tree node colors
        public static int RED = 0;
        public static int BLACK = 1;
        private int intColor; //red or black
        //A red-black tree is a binary search tree with one extra attribute for each node: 
        //the colour, which is either red or black.
        //public int balance;
        //The balance factor of a node is the height of its left subtree 
        //minus the height of its right subtree 
        //and a node with balance factor 1, 0, or −1 is considered balanced. 

        public int Color
        {
            get
            {
                return intColor;
            }

            set
            {
                intColor = value;
            }
        }
     


    }
}
